#ifndef __FRAMEBUFFER
#define __FRAMEBUFFER

/*
basic definition of a variable framebuffer. RGB(A) in 8/32 bit is supported.
*/

// INCLUDES -------------------------------------------------------------------------
#include "base_datatypes.h"	// datatypes: "fNumber", "bool"

// FRAMEBUFFER DATATYPES ------------------------------------------------------------

typedef enum
{
	RGB8,					// RGB values in the range of [0,255]
	RGB32,					// RGB values in floating-point
	RGBA8,					// RGB+Alpha values in the range of [0,255]
	RGBA32,					// RGB+Alpha values in floating-point
	FRAMEBUFFERTYPE_EOL
} framebufferType;

typedef struct
{
	framebufferType type; // type of the framebuffer
	void* buffer;         // memory location of the framebuffer data
	unsigned int width,	  // width in pixels X
	             height;  // height in pixels Y
} framebuffer;

// PIXEL DATATYPES ------------------------------------------------------------------

// ----> RGB
typedef struct
{
	union
	{
		unsigned char value[3];		// unified variant
		struct
		{
			unsigned char red,		// red component
						  green,	// green component
						  blue;		// blue component
		};
	};
} pixelRGB8;

typedef struct
{
	union
	{
		fNumber value[3];	// unified variant
		struct
		{
			fNumber red,	// red component
					green,	// green component
					blue;	// blue component
		};
	};
} pixelRGB32;

// ----> RGBA
typedef struct
{
	union
	{
		unsigned char value[4];		// unified variant
		struct
		{
			unsigned char red,		// red component
						  green,	// green component
						  blue,		// blue component
						  alpha;	// alpha component
		};
	};
} pixelRGBA8;

typedef struct
{
	union {
		fNumber rgba[4];	// unified variant
		struct
		{
			fNumber red,	// red component
					green,	// green component
					blue,	// blue component
					alpha;	// alpha component
		};
	};
} pixelRGBA32;

// FUNCTIONS ------------------------------------------------------------------------

// clear all memory and reset framebuffer engine
void framebufferFreeMemory();

// create a framebuffer held in memory -> RETURNS CREATED SLOT NUMBER
int framebufferCreate(framebufferType type,	// type of framebuffer data
					  unsigned int width,	// width in pixels X
					  unsigned int height);	// height in pixels Y

// modify a framebuffer that was previously created
bool framebufferModify(unsigned int slot,	// slot of the framebuffer stack
					   unsigned int x,		// width/x pixel position
					   unsigned int y,		// height/y pixel position
					   fNumber R,			// RED value
					   fNumber G,			// GREEN value
					   fNumber B,			// BLUE value
					   fNumber A);			// Alpha value

// retrieve raw access to a framebuffer that was previously created
framebuffer* framebufferGetFramebuffer(unsigned int slot);

#endif // __FRAMEBUFFER
